local qizhaobaichu = fk.CreateSkill{
    name = "ym2__qizhaobaichu",
}
Fk:loadTranslationTable{
    ["ym2__qizhaobaichu"] = "奇招百出",
    [":ym2__qizhaobaichu"] = "你可将1/2/3张牌当【树上开花】/【逐近弃远】/【趁火打劫】使用，结算后若你仅有一张手牌，你可以再将之当【出其不意】使用。",
    ["#ym2__qizhaobaichu-unexpectation"] = "奇招百出：是否将最后的手牌当【出其不意】使用？若如此做，请指定目标！",
    ["#ym2__qizhaobaichu0"] = "奇招百出：请先选择一个牌名！",
    ["#ym2__qizhaobaichu1"] = "奇招百出：请将一张牌当【树上开花】使用！",
    ["#ym2__qizhaobaichu2"] = "奇招百出：请将两张牌当【逐近弃远】使用！",
    ["#ym2__qizhaobaichu3"] = "奇招百出：请将三张牌当【趁火打劫】使用！",
}
qizhaobaichu:addEffect("viewas",{
    anim_type = "support",
    pattern = "bogus_flower,chasing_near,looting",
    interaction = function(self,player)
        local all_names = {"bogus_flower", "chasing_near", "looting"}
        local names = player:getViewAsCardNames(qizhaobaichu.name,all_names)
        --[[for _, id in ipairs (all_names) do
            if Self:getMark("ym2__qizhaobaichu_"..id.."-turn") > 0 then
                table.removeOne(names, id)
            end
        end]]--
        if #names > 0 then
            return UI.ComboBox { choices = names, all_choices = all_names }
        end
    end,
    prompt = function (self, player, selected_cards, selected)
        if not self.interaction.data then return "#ym2__qizhaobaichu0" end
        if self.interaction.data == "bogus_flower" then
            return "#ym2__qizhaobaichu1"
        elseif self.interaction.data == "chasing_near" then
            return "#ym2__qizhaobaichu2"
        elseif self.interaction.data == "looting" then
            return "#ym2__qizhaobaichu3"
        end
        return "#ym2__qizhaobaichu0"
    end,
    handly_pile = true,
    card_filter = function(self, player, to_select, selected)
        if not self.interaction.data then return end
        if self.interaction.data == "bogus_flower" then 
            return #selected < 1
        elseif self.interaction.data == "chasing_near" then 
            return #selected < 2
        elseif self.interaction.data == "looting" then 
            return #selected < 3
        end
    end,
    view_as = function(self, player, cards)
        if not self.interaction.data then return end
        if #cards ~= 1 and self.interaction.data == "bogus_flower" then return end
        if #cards ~= 2 and self.interaction.data == "chasing_near" then return end
        if #cards ~= 3 and self.interaction.data == "looting" then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = qizhaobaichu.name
        card:addSubcards(cards)
        return card
    end,
    --[[before_use = function(self, player, use)
        player.room:setPlayerMark(player, "ym2__qizhaobaichu_"..self.interaction.data.."-turn", 1)
    end,]]--
    after_use = function(self, player, use)
        if player:getHandcardNum() == 1 then
            local unexpectation = Fk:cloneCard("unexpectation")
            local max_num = unexpectation.skill:getMaxTargetNum(player, unexpectation)
            local targets = {}
            for _, p in ipairs(player.room:getAllPlayers()) do
                if not player:prohibitUse(unexpectation) and player:canUseTo(unexpectation, p) and not p:isKongcheng() then
                table.insert(targets, p.id)
                end
            end
            if #targets > 0 then
                local tos = player.room:askToChoosePlayers(player,{
                    targets = targets,
                    max_num = max_num,
                    min_num = 1,
                    prompt = "#ym2__qizhaobaichu-unexpectation",
                    skill_name = qizhaobaichu.name,
                    cancelable = true
                })
                if #tos > 0 then
                    --[[local all_names = {"bogus_flower", "chasing_near", "looting"}
                    for _, id in ipairs (all_names) do
                        player.room:setPlayerMark(player, "ym2__qizhaobaichu_"..id.."-turn", 0)
                    end]]--
                    unexpectation.skillName = qizhaobaichu.name
                    for _, id in ipairs(player:getCardIds("h")) do
                        unexpectation:addSubcard(id)
                    end
                    player.room:useCard{
                        from = player.id,
                        card = unexpectation,
                        tos = table.map(tos, function(id) return {id} end),
                        extraUse = true,
                    }
                end
            end
        end
    end,
})
return qizhaobaichu